package Compation;

import java.util.*;

public class countLargestGroup {
    private Map<Integer, Integer> map;

    public static void main(String[] args) {
        int n = 24;
        System.out.println(new countLargestGroup().countLargestGroup(n));
    }

    public int countLargestGroup(int n) {
        map = new HashMap<>();
        for (int i = 1; i <= n; i++) {
            int res = calSum(i);
            map.put(res, map.getOrDefault(res, 0) + 1);
        }
        int maxLength = Collections.max(map.values());
        int res = 0;
        for (int i: map.values()) {
            if (i == maxLength) {
                res += 1;
            }
        }
        return res;
    }

    private int calSum(int n) {
        String s = Integer.toString(n);
        int res = 0;
        for (int i = 0; i < s.length(); i++) {
            res += s.charAt(i) - '0';
        }
        return res;
    }
}
